// IKafkaProducer.cs
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Beauty.Net.Kafka
{
    /// <summary>
    /// Kafka 生产者接口
    /// </summary>
    public interface IKafkaProducer
    {
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="topic">主题</param>
        /// <param name="message">消息</param>
        /// <returns>发送结果</returns>
        Task<DeliveryResult> ProduceAsync(string topic, IKafkaMessage message);

        /// <summary>
        /// 批量发送消息
        /// </summary>
        /// <param name="topic">主题</param>
        /// <param name="messages">消息集合</param>
        /// <returns>发送结果集合</returns>
        Task<IEnumerable<DeliveryResult>> ProduceBatchAsync(string topic, IEnumerable<IKafkaMessage> messages);

        /// <summary>
        /// 事务发送
        /// </summary>
        /// <param name="topic">主题</param>
        /// <param name="messages">消息集合</param>
        /// <returns>发送结果集合</returns>
        Task<IEnumerable<DeliveryResult>> ProduceTransactionAsync(string topic, IEnumerable<IKafkaMessage> messages);
    }

    /// <summary>
    /// 发送结果
    /// </summary>
    public class DeliveryResult
    {
        public string Topic { get; set; } = string.Empty;
        public int Partition { get; set; }
        public long Offset { get; set; }
        public string Key { get; set; } = string.Empty;
        public bool IsSuccess { get; set; }
        public string Error { get; set; } = string.Empty;
    }
}
